package com.lianzhihui.romeex.mvp.model;

import android.content.Context;

import com.blankj.utilcode.util.ToastUtils;
import com.lianzhihui.romeex.MyApplication;
import com.lianzhihui.romeex.R;
import com.lianzhihui.romeex.bean.FirstMinnerFindHomeInfoBean;
import com.lianzhihui.romeex.bean.FirstMinnerFindRecordInfoBean;
import com.lianzhihui.romeex.net.APIConstant;
import com.lianzhihui.romeex.net.HttpManager;
import com.lianzhihui.romeex.net.HttpManagerCallback;
import com.lianzhihui.romeex.net.ResultData;
import com.lianzhihui.romeex.utils.GsonUtil;
import com.lianzhihui.romeex.utils.LogUtil;
import com.zhouyou.http.exception.ApiException;
import com.zhouyou.http.model.HttpParams;

/**
 * @ProjectName: romeex
 * @Package: com.lianzhihui.romeex.mvp.model.base
 * @ClassName: InvitationModellmp
 * @Description: java类作用描述
 * @Author: zhanghong
 * @CreateDate: 2020/11/9 18:18
 * @UpdateUser: 更新者：
 * @UpdateDate: 2020/11/9 18:18
 * @UpdateRemark: 更新说明：
 * @Version: 1.0
 */
public class BaiZhanTingModelImp {


    private Context context;
    BaiZhanTingModelInterface model;

    public BaiZhanTingModelImp(Context context, BaiZhanTingModelInterface model) {
        this.context = context;
        this.model = model;
    }

    /**
     * 头矿首页
     */
    public void requestFirstMinnerFindhome() {
        HttpParams params = new HttpParams();
        new HttpManager(context, new HttpManagerCallback() {
            @Override
            public void onSuccess(ResultData o) {
                LogUtil.info("InvitationModelImp:", o.getCode() + "");
                if (o.getCode() == 200) {
                    FirstMinnerFindHomeInfoBean bean = GsonUtil.GsonToBean(o.getData(), FirstMinnerFindHomeInfoBean.class);

                    model.responseFirstMinnerFindhomeSuccess(bean);
                } else {
                    model.onFailure();
                }
            }

            @Override
            public void onError(ApiException e) {
                if (e.getCode() == 300017) {
                    ToastUtils.showShort(e.getMessage());
                } else {
                    ToastUtils.showShort(MyApplication.mContext.getResources().getString(R.string.text_net_error));
                }

                model.onFailure();
            }
        }).post(APIConstant.FIRSTMINNER_FINDHOME, params);
    }

    /**
     * 头矿挖矿记录
     */
    public void requestFirstMinnerFindrecord(int page, int pageSize) {
        HttpParams params = new HttpParams();
        params.put("page", String.valueOf(page));
        params.put("pageSize", String.valueOf(pageSize));
        new HttpManager(context, new HttpManagerCallback() {
            @Override
            public void onSuccess(ResultData o) {

                if (o.getCode() == 200) {
                    FirstMinnerFindRecordInfoBean bean = GsonUtil.GsonToBean(o.getData(), FirstMinnerFindRecordInfoBean.class);
                    model.responseFirstMinnerFindrecordSuccess(bean);
                } else {
                    model.onFailure();
                }
            }

            @Override
            public void onError(ApiException e) {
                if (e.getCode() == 300017) {
                    ToastUtils.showShort(e.getMessage());
                } else {
                    ToastUtils.showShort(MyApplication.mContext.getResources().getString(R.string.text_net_error));
                }

                model.onFailure();
            }
        }).post(APIConstant.FIRSTMINNER_FINDRECORD, params);
    }

    /**
     * 开启头矿
     */
    public void requestFirstMinnerOpenFirstStatus() {
        HttpParams params = new HttpParams();
        new HttpManager(context, new HttpManagerCallback() {
            @Override
            public void onSuccess(ResultData o) {
                LogUtil.info("InvitationModelImp:", o.getCode() + "");
                if (o.getCode() == 200) {
                    model.responseSuccess();
                } else {
                    model.onFailure();
                }
            }

            @Override
            public void onError(ApiException e) {
//                if (e.getCode() == 300017) {
                ToastUtils.showShort(e.getMessage());
//                } else {
//                    ToastUtils.showShort(MyApplication.mContext.getResources().getString(R.string.text_net_error));
//                }

                model.onFailure();
            }
        }).post(APIConstant.FIRSTMINNER_OPENFIRSTSTATUS, params);
    }
}
